package com.example.f8399.testdemo.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;

import com.example.f8399.testdemo.BaseActivity;
import com.example.f8399.testdemo.R;
import com.example.f8399.testdemo.adapter.RxAndroidAdapter;
import com.example.f8399.testdemo.bean.AppBean;
import com.example.f8399.testdemo.databinding.ActivityRxAndroidManagerBinding;
import com.example.f8399.testdemo.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * RxJava RxAndroid 方面的知识都是在这里管理的
 */
public class RxAndroidManagerAc extends BaseActivity {

    ActivityRxAndroidManagerBinding mBinding;
    private List<AppBean> mList = new ArrayList<>();
    private RxAndroidAdapter mAdapter;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_rx_android_manager);

        LinearLayoutManager layout = new LinearLayoutManager(this);
        mBinding.recyclerView.setLayoutManager(layout);
        mBinding.recyclerView.addItemDecoration(new DividerItemDecoration(this, layout.getOrientation()));


        mList.add(new AppBean<Object>("first", RxFirstActivity.class));


        mAdapter = new RxAndroidAdapter(this, mList);
        mBinding.recyclerView.setAdapter(mAdapter);


        mAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                Class<AppCompatActivity> cls = (Class<AppCompatActivity>) mList.get(position).getCls();
                goActivity(cls);
            }
        });
    }
}
